import go from 'gojs'
import request from '@/utils/request'
import Cookies from 'js-cookie'
import axios from 'axios'
import store from '@/store'
import { getToken } from '@/utils/auth'
/**
 * 列表
 * @returns {*}
 */
export function list(pageNo, pageSize, proprietorshipStatus, resourceApplyStatusEnumStatus, category, type, userId) {
  return request({
    url: '/cloud/jcce/v1.0/kt1/dataResource',
    method: 'get',
    params: {
      pageNo: pageNo,
      pageSize: pageSize,
      proprietorshipStatus: proprietorshipStatus,
      resourceApplyStatusEnumStatus: resourceApplyStatusEnumStatus,
      category: category,
      type: type,
      userId: userId
    }
  })
}

export function downloadfile(id) {
  return request({
    url: '/admin/api/sysUser/noPermission/downloadWord',
    method: 'get',
    params: {
      id: id,
    },
    responseType: 'blob'
  })
}

/**
 * 申请
 * @returns {*}
 */
export function applyDataResource(resourceId, userId, applyNote , usageRightDetail,startTime,endTime) {
  return request({
    // url: `/cloud/jcce/v1.0/kt1/userResourceApply/${resourceId}/${userId}`,
    url: '/cloud/jcce/v1.0/kt1/userResourceApply',
    method: 'post',
    params: {
      resourceId: resourceId,
      userId: userId,
      applyNote: applyNote,
      usageRightDetail: usageRightDetail,
      startTime: startTime,
      endTime: endTime
    }
  })
}

export function downloadNew(id, fileType) {
  axios.get('/cloud/jcce/v1.0/kt1/download?id=' + id + '&fileType=' + fileType, {
    headers: {
      Authorization: getToken()
    },
    responseType: 'blob'
  }).then(res => {
    // 这里的type最好参考Response Headers里面的content-type，有可能是application/vnd.ms-excel
    const blob = new Blob([res.data])
    // 获取文件名，根据自己需要的分割
    const content = res.headers['content-disposition']
    const index = content.indexOf('filename=')
    let fileName = content.substring(index + 9) // 截取文件名
    fileName = decodeURIComponent(fileName).replace(new RegExp('"', 'g'), '')
    const a = document.createElement('a')
    const url = window.URL.createObjectURL(blob)
    a.href = url
    a.download = fileName
    document.body.appendChild(a)
    a.style.display = 'none'
    a.click()
    document.body.removeChild(a)
    window.URL.revokeObjectURL(url)
  })
}

/**
 * 已废弃，由于request.js 中写的不对，文件名称自动拼接了文件名称的前后缀，忘后人注意
 * @returns {*}
 */
export function downloadDataFile(resourceId) {
  return request({
    // url: `/cloud/jcce/v1.0/kt1/userResourceApply/${resourceId}/${userId}`,
    url: '/cloud/jcce/v1.0/kt1/download',
    method: 'get',
    params: {
      id: resourceId,
      fileType: 'DATA_FILE'
    },
    responseType: 'blob'
  })
}

/**
 * 搜索条件
 * @returns {*}
 */
export function search(type) {
  return request({
    url: '/cloud/jcce/v1.0/kt1/dataResource/dict/' + type,
    method: 'get'
  })
}

export default {
  name: 'authentic',
  data() {
    return {
      dialogVisible: false,
      dialogVisibleH: false,
      hashData: [{
        block: 100000,
        miner: '0x9a74e0aecf1dd5162d9802c60527c82230fdf703',
        time: 20,
        count: 22,
        fee: 0.00101
      },{
        block: 100001,
        miner: '0x000000633b68f5d6d3a76593eeb815b4663bcbe0',
        time: 5,
        count: 15,
        fee: 0.00231
      },{
        block: 100002,
        miner: '0x68d30f47f19c06bccef4bc7fae2dc12fca3e0dc9',
        time: 16,
        count: 12,
        fee: 0.00098
      },{
        block: 100003,
        miner: '0x68d30f47f19c07bccef4bc7fae2dc12fca3e0dc6',
        time: 13,
        count: 30,
        fee: 0.00324
      }],
      form: {
        rights: [],
        startTime:'',
        endTime:'',
        note: '',
        dataResourceId :''
      },
      rightsList: [

      ],
      fileServerBaseUrl: '/cloud/jcce/v1.0/kt1/download?fileType=IMAGE_FILE&id=',
      firstInfo: {
        id: 0,
        value: '',
        localName: '全部'
      },
      imageUrl: '',
      imageAlt: '',
      categoryList: [],
      typeList: [],
      authorityList: [],
      applyList: [],
      selectedCategory: '',
      selectedType: '',
      proprietorshipStatus: '',
      resourceApplyStatusEnumStatus: '',
      dataList: [], // 数据列表
      totalItems: 0, // 总数据条数
      pageSize: 10, // 每页显示条数
      currentPage: 1, // 当前页码
      showDataDetail: false,
      currentDataDetail: {
        ownerships: []
      },
      showSupplierDetail: false,
      currentSupplierDetail: {},
      dataDiagram: null,
      supplierDiagram: null,
      activeName: '1',
      userImg: '/static/kt1/user.svg',
      reportImg: '/static/kt1/report.svg',
      userId : null

    }
  },
  mounted() {
    this.getBaseDatas()
    this.searchForList()
    const userInfo = JSON.parse(Cookies.get('user'))
    this.userId = userInfo.userId;
  },
  methods: {
    openDialog() {
      this.dialogVisible = true
    },
    submitForm() {
      if (!this.form.rights.length || !this.form.note) {
        this.$message({
          type: 'error',
          message: '请填写完整信息'
        })
        return
      }
      const userInfo = JSON.parse(Cookies.get('user'))
      applyDataResource(this.form.dataResourceId, userInfo.userId, this.form.note ,this.form.rights.toString(),this.form.startTime,this.form.endTime).then((data) => {
        if (data.code === 0) {
          this.searchForList()
          this.$message({
            type: 'success',
            message: '申请成功'
          })
          this.dialogVisible = false
        }
      }).catch((error) => {
        this.$message({
          type: 'error',
          message: error.msg
        })
      })
    }
  ,
    checkStatus(status) {
      var type = ''
      switch (status) {
        case 'NOT_SUBMITTED':
          break
        case 'SUBMITTED':
          type = 'info'
          break
        case 'AUDIT_APPROVE':
          type = 'warning'
          break
        case 'REJECTED':
          type = 'danger'
          break
        case 'DOWNLOADABLE':
          type = 'success'
          break
      }
      return type
    },
    buttonCheckStatus(status) {
      var type = ''
      switch (status) {
        case 'NOT_SUBMITTED':
          type = 'primary'
          break
        case 'SUBMITTED':
          type = 'info'
          break
        case 'AUDIT_APPROVE':
          type = 'warning'
          break
        case 'REJECTED':
          type = 'danger'
          break
        case 'DOWNLOADABLE':
          type = 'success'
          break
      }
      return type
    },
    buttonLabel(resourceApplyStatus) {
      var name = ''
      switch (resourceApplyStatus) {
        case 'NOT_SUBMITTED':
          name = '数据申请'
          break
        case 'SUBMITTED':
          name = '数据申请'
          break
        case 'AUDIT_APPROVE':
          name = '数据申请'
          break
        case 'REJECTED':
          name = '重新申请'
          break
        case 'DOWNLOADABLE':
          name = '下载'
          break
      }
      return name
    },
    checkButtonShow(proprietorshipStatus, resourceApplyStatus) {
      var flag = false
      if (proprietorshipStatus === 'APPROVED') {
        if (resourceApplyStatus !== 'SUBMITTED') {
          if (resourceApplyStatus !== 'AUDIT_APPROVE') {
            flag = true
          }
        }
      }
      return flag
    },
    buttonOnclick(resourceApplyStatus, id,usageRightDetail) {
      switch (resourceApplyStatus) {
        case 'NOT_SUBMITTED': // 数据申请
          this.dialogVisible = true
          this.form.dataResourceId = id;
          this.rightsList = [];
          usageRightDetail.split(",").forEach(item => {
            this.rightsList.push({
              value: item,
              label: item
            })
          })
          // this.submitForm(id)
          break
        case 'REJECTED': // 重新申请
          // this.apply(id)
          this.dialogVisible = true
          this.form.dataResourceId = id;
          this.rightsList = [];
          usageRightDetail.split(",").forEach(item => {
            this.rightsList.push({
              value: item,
              label: item
            })
          })
          break
        case 'DOWNLOADABLE': // 下载
          downloadNew(id, 'DATA_FILE')
          break
      }
    },
    download(id, type) {
      downloadNew(id, type)
    },
    apply(id) {
      this.$prompt('请输入备注', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        // inputErrorMessage: '邮箱格式不正确'
        inputValidator: (value) => {
          if (!value) {
            return '请输入内容' // 输入框为空时的错误提示
          } else if (value.length > 50) {
            return '内容不能超过50个字符' // 输入内容超过50个字符时的错误提示
          } else {
            return true // 校验通过
          }
        }
      }).then(({ value }) => {
        const userInfo = JSON.parse(Cookies.get('user'))
        applyDataResource(id, userInfo.userId, value).then((data) => {
          if (data.code === 0) {
            this.searchForList()
            this.$message({
              type: 'success',
              message: '申请成功'
            })
          }
        }).catch((error) => {
          this.$message({
            type: 'error',
            message: error.msg
          })
        })
      }).catch(() => {
      })
    },
    getBaseDatas() {
      // 分类
      search('category').then((data) => {
        this.categoryList = data.data
        this.categoryList.unshift(this.firstInfo)
      }).catch((error) => {
        console.log(error)
      })
      // 类型
      search('type').then((data) => {
        this.typeList = data.data
        this.typeList.unshift(this.firstInfo)
      }).catch((error) => {
        console.log(error)
      })
      // 确权状态
      this.authorityList = [
        { id: '0', label: '全部', value: '' },
        { id: '1', label: '待确认', value: 'PENDING' },
        { id: '2', label: '确权中', value: 'CONFIRMING' },
        { id: '3', label: '已通过', value: 'APPROVED' },
        { id: '4', label: '驳回', value: 'REJECTED' }
      ]
      // 申请状态
      this.applyList = [
        { id: '0', label: '全部', value: '' },
        { id: '1', label: '未提交', value: 'NOT_SUBMITTED' },
        { id: '2', label: '已提交', value: 'SUBMITTED' },
        { id: '3', label: '审核通过', value: 'AUDIT_APPROVE' },
        { id: '4', label: '已驳回', value: 'REJECTED' },
        { id: '5', label: '可下载', value: 'DOWNLOADABLE' }
      ]
    },
    searchForList(vr) {
      if (vr === 0) { // 点击筛选的时候，设置为第一页
        this.currentPage = 1
      }
      // 获取用户信息
      const userInfo = JSON.parse(Cookies.get('user'))
      list(this.currentPage, this.pageSize, this.proprietorshipStatus, this.resourceApplyStatusEnumStatus, this.selectedCategory, this.selectedType, userInfo.userId).then((data) => {
        this.dataList = data.data.pageData
        this.totalItems = data.data.total
        this.dataList.forEach(item => {
          item.imageUrl = this.fileServerBaseUrl + item.id
        })
      }).catch((error) => {
        console.log(error)
      })
    },
    downloadFile(id){
      downloadfile(id)
        .then((resp) => {
          // debugger
          // const content = resp; // 后台返回二进制数据
          // const blob = new Blob([content]);
          // const fileName = '访客审批单.docx';
          // if ('download' in document.createElement('a')) { // 非IE下载
          //   const elink = document.createElement('a');
          //   elink.download = fileName;
          //   elink.style.display = 'none';
          //   elink.href = URL.createObjectURL(blob);
          //   document.body.appendChild(elink);
          //   elink.click();
          //   URL.revokeObjectURL(elink.href); // 释放URL 对象
          //   document.body.removeChild(elink);
          // } else { // IE10+下载
          //   navigator.msSaveBlob(blob, fileName);
          // }
        });
    },
    create() {
      this.$router.push({ name: 'authenticCreate', params: { previousPage: 'pubCloud', routeLevel: 3 } })
    },
    handlePageChange(page) {
      this.currentPage = page
      this.searchForList()
    },
    handleSizeChange(size) {
      this.pageSize = size
      this.searchForList()
    },
    toDataDetail(item) {
      // eslint-disable-next-line no-empty
      if (item === -1) {
        this.currentDataDetail = {
          id: 0,
          image: '/static/kt1/authenticImg.png',
          name: '电商经营分析报告',
          isAuthorized: false,
          description: '从经营、工商、司法等多维度数据分析电商客户综合实力和资信，降低金融机构的信息搜寻成本。',
          supplier: '供应商J',
          dataSupplier: '供应商J',
          dataCategory: '生产管理',
          dataType: '数据报告',
          price: '￥70',
          dataIdentification: '1',
          registrationTime: '2022-08-08',
          dataSize: '18 MB',
          dataFormat: '.docx',
          ownRight: 'XXX有限公司',
          tradingRightList: [{ id: 0, name: '用户1' }, { id: 1, name: '用户2' }, { id: 2, name: '用户3' }],
          usingRightList: [{ id: 0, name: '用户1' }, { id: 1, name: '用户2' }, { id: 2, name: '用户3' }],
          dataExample: [{ label: '用户留存率', value: '33%' }, { label: '用户数量', value: '' },
            { label: '年度销售额', value: '100w' }, { label: '季度销售额', value: '33w' }, {
              label: '商品成本',
              value: '20w'
            },
            { label: '运营费用', value: '20w' }, { label: '市场推广费用', value: '20w' }, {
              label: '人力资源费用',
              value: '20w'
            },
            { label: '利润', value: '20w' }, { label: '净利率', value: '20%' }]
        }
      } else {
        this.currentDataDetail = item
        console.log(item.id)
      }
      this.showSupplierDetail = false
      this.showDataDetail = true
      this.initDataGraph()
    },
    initDataGraph() {
      var $$ = go.GraphObject.make // for conciseness in defining templates
      const nodes = []
      const links = []

      console.log(this.currentDataDetail)
      nodes.push({
        key: '0',
        text: this.currentDataDetail.name,
        source: this.reportImg
      })
      nodes.push({
        key: '1',
        text: '所有权'
      })
      nodes.push({
        key: '1-1',
        text: this.currentDataDetail.ownRight,
        source: this.userImg
      })
      nodes.push({
        key: '2',
        text: '交易权'
      })
      nodes.push({
        key: '3',
        text: '使用权'
      })
      links.push({ from: '0', to: '1' })
      links.push({ from: '0', to: '2' })
      links.push({ from: '0', to: '3' })
      links.push({ from: '1', to: '1-1' })

      for (let i = 0; i < this.currentDataDetail.tradingRightList.length; i++) {
        nodes.push({
          key: 2 + '-' + this.currentDataDetail.tradingRightList[i].id,
          text: this.currentDataDetail.tradingRightList[i].name,
          source: this.userImg
        })
        links.push({ from: '2', to: 2 + '-' + this.currentDataDetail.tradingRightList[i].id })
      }
      for (let i = 0; i < this.currentDataDetail.usingRightList.length; i++) {
        nodes.push({
          key: 3 + '-' + this.currentDataDetail.usingRightList[i].id,
          text: this.currentDataDetail.usingRightList[i].name,
          source: this.userImg
        })
        links.push({ from: '3', to: 3 + '-' + this.currentDataDetail.usingRightList[i].id })
      }

      const mygoChart = document.getElementById('myDiagramDiv')
      console.log(mygoChart)
      const diagramParentDiv = document.getElementById('diagramParentDiv')
      if (mygoChart) {
        diagramParentDiv.removeChild(mygoChart)
      }
      const div = document.createElement('div')
      div.setAttribute('id', 'dataDiagramDiv')
      div.setAttribute('style', 'width:100%; height:45vh')
      diagramParentDiv.appendChild(div)
      this.dataDiagram = $$(go.Diagram, 'dataDiagramDiv', {
        // layout: $$(go.GridLayout)
        'toolManager.mouseWheelBehavior': go.ToolManager.WheelZoom,
        initialAutoScale: go.Diagram.Uniform,
        // start everything in the middle of the viewport
        initialContentAlignment: go.Spot.Center,
        // disable user copying of parts
        allowCopy: false,
        layout: $$(go.LayeredDigraphLayout, {
          layerSpacing: 40,
          columnSpacing: 20,
          direction: 90,
          setsPortSpots: false
          // initializeOption:go.LayeredDigraphLayout.InitNaive,
          // layeringOption:go.LayeredDigraphLayout.LayerLongestPathSink
        })
      })
      this.dataDiagram.linkTemplate = $$(
        go.Link,
        {
          curve: go.Link.Bezier
        },
        $$(
          go.Shape,
          {
            strokeWidth: 1,
            name: 'PIPE',
            stroke: '#eeeeee'
          }
        ),
        $$(
          go.Shape,
          { toArrow: 'Standard', stroke: '#eeeeee', scale: 1 }
        ),
        $$(
          go.TextBlock,
          {
            textAlign: 'center',
            font: '16pt helvetica, arial, sans-serif',
            segmentOffset: new go.Point(0, 10),
            margin: 4,
            editable: false
          }
        )
      )

      this.dataDiagram.nodeTemplate = $$(
        go.Node,
        'Vertical',
        $$(go.Panel, 'Auto',
          $$(go.Shape, 'RoundedRectangle',
            {
              fill: null, // 设置内部填充的颜色
              stroke: 'rgba(255,255,255,0)'// 设置边框的颜色
            }
          ),
          $$(go.Panel, 'Table',
            $$(go.Picture, {
              row: 0,
              column: 0,
              rowSpan: 2,
              desiredSize: new go.Size(20, 23)
            }, new go.Binding('source'), new go.Binding('visible', 'key', this.pictureVisible)),
            $$(go.TextBlock, {
              row: 2,
              column: 0,
              rowSpan: 2,
              alignment: go.Spot.Top,
              margin: 5,
              font: 'bold 14px sans-serif ',
              stroke: '#ffffff'
            }, new go.Binding('text'))
          )
        )
      )
      this.dataDiagram.model = new go.GraphLinksModel(nodes, links)
    },

    toSupplierDetail(supplier) {
      this.showSupplierDetail = false // 假装刷新
      const self = this
      setTimeout(function() {
        console.log(supplier)
        // getSupplierDetail
        self.currentSupplierDetail = {
          ownRightList: [{ id: 0, name: '数据1' }, { id: 1, name: '数据2' }, { id: 2, name: '数据3' }],
          tradingRightList: [{ id: 3, name: '数据A' }, { id: 4, name: '数据B' }, { id: 5, name: '数据C' }],
          usingRightList: [{ id: 6, name: '数据1' }, { id: 7, name: '数据2' }, { id: 8, name: '数据3' }],
          confirmedDataList: [
            {
              id: 0,
              name: '电商经营分析报告',
              category: '生产管理',
              type: '数据报告',
              registrationTime: '2022-07-08',
              confirmedTime: '2022-08-08'
            },
            {
              id: 1,
              name: '电商经营分析报告1',
              category: '金融科技',
              type: '数据报告',
              registrationTime: '2022-07-08',
              confirmedTime: '2022-08-08'
            },
            {
              id: 2,
              name: '电商经营分析报告2',
              category: '生产管理',
              type: '数据报告',
              registrationTime: '2022-07-08',
              confirmedTime: '2022-08-08'
            },
            {
              id: 3,
              name: '电商经营分析报告3',
              category: '人工智能',
              type: '数据报告',
              registrationTime: '2022-07-08',
              confirmedTime: '2022-08-08'
            },
            {
              id: 4,
              name: '电商经营分析报告4',
              category: '金融科技',
              type: '数据报告',
              registrationTime: '2022-07-08',
              confirmedTime: '2022-08-08'
            }],
          unconfirmedDataList: [
            {
              id: 5,
              name: '电商经营分析报告5',
              category: '金融科技',
              type: '数据报告',
              registrationTime: '2022-07-08'
            },
            {
              id: 6,
              name: '电商经营分析报告6',
              category: '生产管理',
              type: '数据报告',
              registrationTime: '2022-07-08'
            },
            {
              id: 7,
              name: '电商经营分析报告7',
              category: '人工智能',
              type: '数据接口',
              registrationTime: '2022-07-08'
            },
            { id: 8, name: '电商经营分析报告8', category: '生产管理', type: '其他', registrationTime: '2022-07-08' }],
          authorisedTradingList: [
            {
              id: 0,
              name: '电商经营分析报告',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商A'
            },
            {
              id: 1,
              name: '电商经营分析报告1',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商B'
            },
            {
              id: 2,
              name: '电商经营分析报告2',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商C'
            },
            {
              id: 3,
              name: '电商经营分析报告3',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商D'
            },
            {
              id: 4,
              name: '电商经营分析报告4',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商E'
            }],
          authorisedUsingList: [
            {
              id: 5,
              name: '电商经营分析报告5',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商A'
            },
            {
              id: 6,
              name: '电商经营分析报告6',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商B'
            },
            {
              id: 7,
              name: '电商经营分析报告7',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商C'
            },
            {
              id: 8,
              name: '电商经营分析报告8',
              category: '金融科技',
              type: '数据报告',
              authorisedTime: '2022-07-08',
              authorizedSupplier: '供应商D'
            }],
          purchasedTradingList: [
            {
              id: 0,
              name: '电商经营分析报告A',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商A'
            },
            {
              id: 1,
              name: '电商经营分析报告1',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商B'
            },
            {
              id: 2,
              name: '电商经营分析报告2',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商C'
            },
            {
              id: 3,
              name: '电商经营分析报告3',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商D'
            },
            {
              id: 4,
              name: '电商经营分析报告4',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商E'
            }],
          purchasedUsingList: [
            {
              id: 5,
              name: '电商经营分析报告5',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商A'
            },
            {
              id: 6,
              name: '电商经营分析报告6',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商B'
            },
            {
              id: 7,
              name: '电商经营分析报告7',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商C'
            },
            {
              id: 8,
              name: '电商经营分析报告8',
              category: '金融科技',
              type: '数据报告',
              purchasedTime: '2022-07-08',
              authorizedSupplier: '供应商D'
            }]
        }
        self.currentSupplierDetail.name = supplier
        self.showDataDetail = false
        self.showSupplierDetail = true
        self.initSupplierGraph()
      }, 100)
    },
    formatDateTime(row, column, cellValue) {
      const date = new Date(parseInt(cellValue))
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + date.getDate()).slice(-2)
      const hours = ('0' + date.getHours()).slice(-2)
      const minutes = ('0' + date.getMinutes()).slice(-2)
      const seconds = ('0' + date.getSeconds()).slice(-2)
      debugger
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    },
    getSupplierRight(item) {
      console.log(item)
      const rightData = {
        ownRightList: [{ id: 0, name: '数据1' }, { id: 1, name: '数据2' }, { id: 2, name: '数据3' }],
        tradingRightList: [{ id: 3, name: '数据A' }, { id: 4, name: '数据B' }, { id: 5, name: '数据c' }],
        usingRightList: [{ id: 6, name: '数据1' }, { id: 7, name: '数据2' }, { id: 8, name: '数据3' }]
      }
      return rightData
    },
    pictureVisible(key, e) {
      const nodeData = e.part.data
      return !!nodeData.source
    },
    initSupplierGraph() {
      var $$ = go.GraphObject.make // for conciseness in defining templates
      const nodes = []
      const links = []

      console.log(this.currentSupplierDetail)
      nodes.push({
        key: '0',
        text: this.currentSupplierDetail.name,
        source: this.userImg
      })
      nodes.push({
        key: '1',
        text: '所有权'
      })
      nodes.push({
        key: '2',
        text: '交易权'
      })
      nodes.push({
        key: '3',
        text: '使用权'
      })
      links.push({ from: '0', to: '1' })
      links.push({ from: '0', to: '2' })
      links.push({ from: '0', to: '3' })
      for (let i = 0; i < this.currentSupplierDetail.ownRightList.length; i++) {
        nodes.push({
          key: 1 + '-' + this.currentSupplierDetail.ownRightList[i].id,
          text: this.currentSupplierDetail.ownRightList[i].name,
          source: this.reportImg
        })
        links.push({ from: '1', to: 1 + '-' + this.currentSupplierDetail.ownRightList[i].id })
      }
      for (let i = 0; i < this.currentSupplierDetail.tradingRightList.length; i++) {
        nodes.push({
          key: 2 + '-' + this.currentSupplierDetail.tradingRightList[i].id,
          text: this.currentSupplierDetail.tradingRightList[i].name,
          source: this.reportImg
        })
        links.push({ from: '2', to: 2 + '-' + this.currentSupplierDetail.tradingRightList[i].id })
      }
      for (let i = 0; i < this.currentSupplierDetail.usingRightList.length; i++) {
        nodes.push({
          key: 3 + '-' + this.currentSupplierDetail.usingRightList[i].id,
          text: this.currentSupplierDetail.usingRightList[i].name,
          source: this.reportImg
        })
        links.push({ from: '3', to: 3 + '-' + this.currentSupplierDetail.usingRightList[i].id })
      }

      const mygoChart = document.getElementById('supplierDiagramDiv')
      console.log(mygoChart)
      const supplierParentDiv = document.getElementById('supplierParentDiv')
      if (mygoChart) {
        supplierParentDiv.removeChild(mygoChart)
      }
      const div = document.createElement('div')
      div.setAttribute('id', 'supplierDiagramDiv')
      div.setAttribute('style', 'width:100%; height:45vh')
      supplierParentDiv.appendChild(div)
      this.supplierDiagram = $$(go.Diagram, 'supplierDiagramDiv', {
        // layout: $$(go.GridLayout)
        'toolManager.mouseWheelBehavior': go.ToolManager.WheelZoom,
        initialAutoScale: go.Diagram.Uniform,
        // start everything in the middle of the viewport
        initialContentAlignment: go.Spot.Center,
        // disable user copying of parts
        allowCopy: false,
        layout: $$(go.LayeredDigraphLayout, {
          layerSpacing: 40,
          columnSpacing: 20,
          direction: 90,
          setsPortSpots: false
          // initializeOption:go.LayeredDigraphLayout.InitNaive,
          // layeringOption:go.LayeredDigraphLayout.LayerLongestPathSink
        })
      })
      this.supplierDiagram.linkTemplate = $$(
        go.Link,
        {
          curve: go.Link.Bezier
        },
        $$(
          go.Shape,
          {
            strokeWidth: 1,
            name: 'PIPE',
            stroke: '#eeeeee'
          }
        ),
        $$(
          go.Shape,
          { toArrow: 'Standard', stroke: '#eeeeee', scale: 1 }
        ),
        $$(
          go.TextBlock,
          {
            textAlign: 'center',
            font: '16pt helvetica, arial, sans-serif',
            segmentOffset: new go.Point(0, 10),
            margin: 4,
            editable: false
          }
        )
      )

      this.supplierDiagram.nodeTemplate = $$(
        go.Node,
        'Vertical',
        $$(go.Panel, 'Auto',
          $$(go.Shape, 'RoundedRectangle',
            {
              fill: null, // 设置内部填充的颜色
              stroke: 'rgba(255,255,255,0)'// 设置边框的颜色
            }
          ),
          $$(go.Panel, 'Table',
            $$(go.Picture, {
              row: 0,
              column: 0,
              rowSpan: 2,
              desiredSize: new go.Size(20, 23)
            }, new go.Binding('source'), new go.Binding('visible', 'key', this.pictureVisible)),
            $$(go.TextBlock, {
              row: 2,
              column: 0,
              rowSpan: 2,
              alignment: go.Spot.Top,
              margin: 5,
              font: 'bold 14px sans-serif ',
              stroke: '#ffffff'
            }, new go.Binding('text'))
          ))
      )
      this.supplierDiagram.model = new go.GraphLinksModel(nodes, links)
    }
  },
  filters: {
    formatDate(timestamp) {
      const date = new Date(parseInt(timestamp))
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + date.getDate()).slice(-2)
      return `${year}-${month}-${day}`
    },
    formatDateTime(timestamp) {
      const date = new Date(parseInt(timestamp))
      const year = date.getFullYear()
      const month = ('0' + (date.getMonth() + 1)).slice(-2)
      const day = ('0' + date.getDate()).slice(-2)
      const hours = ('0' + date.getHours()).slice(-2)
      const minutes = ('0' + date.getMinutes()).slice(-2)
      const seconds = ('0' + date.getSeconds()).slice(-2)
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    }
  }
}
